package com.example.logistics_manage.service.serviceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.logistics_manage.Utils.IsEmptyExam;
import com.example.logistics_manage.mapper.OrdersMapper;
import com.example.logistics_manage.pojo.Orders;
import com.example.logistics_manage.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrdersService extends ServiceImpl<OrdersMapper, Orders> implements IOrderService {
    @Autowired
    OrdersMapper ordersMapper;
    @Autowired
    IsEmptyExam isEmptyExam;
    @Override
    public IPage<Orders> findAllQueryPage(Integer current,Integer size) {
        return ordersMapper.findAllQueryPage(Page.of(current,size));
    }

    @Override
    public Orders findOrdersById(Integer orderId) {
        return getById(orderId);
    }

    @Override
    public int updateOrders(Orders orders) {
       return ordersMapper.updateOrders(orders);
    }

    @Override
    public boolean deleteOrdersById(Integer orderId) {
        return removeById(orderId);
    }

    @Override
    public IPage<Orders> findOrdersByData(Orders orders,Integer current,Integer size) {
        if (isEmptyExam.examOrdersData(orders)){
            return ordersMapper.findAllQueryPage(Page.of(current,size));
        }

        if (orders.getOrderId() != null){
            return ordersMapper.findOrdersById(Page.of(current,size),orders.getOrderId());
        }
        if (orders.getCustomerName() != null && !orders.getCustomerName().equals("")){
            return ordersMapper.findOrderByName(Page.of(current,size),orders.getCustomerName());
        }
        return ordersMapper.findOrderByConsignor(Page.of(current,size),orders.getConsignor());
    }
}
